#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
    int fd;
    fd = open("/dev/fb0", O_RDWR);
    if (fd < 0)
    {
        printf("open /dev/fb0 failed error: %s\n", strerror(errno));
        return -1;
    }

    printf("open /dev/fb0 success\n");

    int buf[480][800] = {0};
    for (int i = 0; i < 480; i++)
    {
        for (int j = 0; j < 800; j++)
        {
            if (i < 160)
            {
                buf[i][j] = 0x00000000; // 黑色
            }
            else if (i < 320)
            {
                buf[i][j] = 0x00FF0000; // 红色
            }
            else
            {
                buf[i][j] = 0x00FFFF00; // 黄色
            }
        }
    }

    int res = write(fd, buf, sizeof(buf));
    printf("write %d bytes\n", res);

    close(fd);
    return 0;
}